/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
using namespace std;
const int N=61;

int main_1061()
{
    char days[7][4]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
    char hours[]="0123456789ABCDEFGHIJKLMN";
    char c1[N]={0},c2[N]={0},c3[N]={0},c4[N]={0};
    scanf("%s%s%s%s",c1,c2,c3,c4);
    char day,hour;
    int minite,i,nth,len1=min(strlen(c1),strlen(c2)),len2=min(strlen(c3),strlen(c4));
    for (i=0;i<len1 ;++i )
    {
        if ((c1[i]==c2[i])&&(c1[i]>='A'&&c1[i]<='G'))
        {
            day=c1[i];
            break;
        }
    }
    for (int j=i+1;j<len1 ;++j )
    {
        if ((c1[j]==c2[j])&&((c1[j]>='0'&&c1[j]<='9')||(c1[j]>='A'&&c1[j]<='N')))
        {
            hour=c1[j];
            break;
        }
    }
    for (int k=0;k<24 ;++k )
    {
        if (hour==hours[k])
        {
            nth=k;
        }
    }
    for (minite=0; minite<len2;++minite )
    {
        if ((c3[minite]==c4[minite])&&(isalpha(c3[minite])))
        {
            break;
        }
    }
    printf("%s %02d:%02d",days[day-'A'],nth,minite);
	return 0;
}
